package com.cdl.controller; 																

import org.slf4j.Logger;		
import org.slf4j.LoggerFactory;		
import org.springframework.beans.factory.annotation.Autowired;							  
import org.springframework.stereotype.Controller;										  
import org.springframework.web.bind.annotation.RequestMapping;							  
import org.springframework.web.bind.annotation.ResponseBody;						      	  
import com.cdl.entity.Employee;													  
import com.cdl.response.DataResponse;													  
import com.cdl.response.FormResponse;													  
import com.cdl.response.PageResponse;													  
import com.cdl.response.SimpleResponse;													  
import com.cdl.service.EmployeeService;												  
import com.github.pagehelper.PageInfo;												  


@Controller 																				  
@RequestMapping("employee")															  
public class EmployeeController{  														  
	    private static Logger logger = LoggerFactory.getLogger(EmployeeController.class);	  
		@Autowired																			  
		EmployeeService employeeServiceImpl ;															  
 	/**  																				  
 	 * 跳转到主页面  																			  
 	 * @return  																		  
 	 */  																				  
 	@RequestMapping("/main")  														  
 	public String  toMain(){  															  
 		logger.info("跳转到主页面-->employee/main");  										  
 		return "employee/main";  												      
 	}																					  
 	/** 																				  
 	 * 跳转到查询页面 																		  
	     * @return 																			  
		 */ 																				  
		@RequestMapping("/query") 														  
		public String  toQuery(){ 															  
		 	logger.info("跳转到查询页面-->employee/query"); 									  
		 	return "employee/query"; 													  
		} 																					  
	    /**   																				  
	     * 跳转到列表页面   																		  
	     * @return   																		  
      */   
	    @RequestMapping("/list")   														  
	    	public String  toList(){   														  
	    	logger.info("跳转到列表页面-->employee/list");   									  
	    	return "employee/list";   														  
		}   																				  
		/**   																				  
		 * 跳转到操作表单页面   																	  
		 * @return   																		  
		 */   																				  
		@RequestMapping("/form")   														  
		public String toForm(){   															  
			logger.info("跳转到操作表单页面-->employee/form");   								  
			return "employee/form";   														  
		}		   																			  
    	/**   																				  
    	 * 跳转到明细页面   																		  
    	 * @param id   																		  
    	 * @return   																		  
    	 */   																				  
    	@RequestMapping("/detail")   														  
    	public String toDetail(String id){   												  
    		logger.info("跳转到明细页面-->employee/detail");  									  
    		return "employee/detail";   													  
    	}   																				  
		/***		  																		  
		 * 查询列表		  																	  
		 * @param user		  																  
		 * @return		  																	  
		 */		  																		      
		@ResponseBody	  																	  
		@RequestMapping("/getList")	  													  
		public PageResponse<Employee> getList(Employee employee){  			  
			logger.info("获取数据列表--->"+employee.toString());  						  
			PageInfo<Employee> page = employeeServiceImpl.getPage(employee);  				  
			PageResponse<Employee> response = new PageResponse<Employee>() ;	  	  
			response.setData(page);  														  
			return response ;  																  
		}  																					  
		/**																					  
		 * 查询单条																			  
		 * @param employee															  
		 * @return																		      
		 */																					  
		@ResponseBody																		  
		@RequestMapping("/get")															  
		public DataResponse<Employee> get(Employee employee){				  
			logger.info("获取单条数据--->"+employee.toString());						  
			Employee data = employeeServiceImpl.get(employee);		                          
			DataResponse<Employee> response = new DataResponse<Employee>();	      
			response.setData(data);		                                                      
			return response ;		                                                          
		}																					  
		/*** 																	              
		 * 新增 																			      
		 * @param employee 															  
		 */  																				  
		@ResponseBody  																		  
		@RequestMapping("/add")  															  
		public FormResponse<String> add(Employee employee){  					  
			logger.info("新增数据-->"+employee.toString());  							  
			FormResponse<String> response = new FormResponse<String>();  		  			  
			if(response.isSuccess()){  														  
				employeeServiceImpl.add(employee);  												  
				response.setMessage("新增成功！");  											  
			}else{ 																			  
				response.setMessage("新增失败！");  											  
			}  																				  
			return response;  															      
		}  																					  
		/***  																				  
		 * 修改 																			      
		 * @param employee  															  
		 */  																				  
		@ResponseBody  																		  
		@RequestMapping("/update")  														  
		public FormResponse<Void> update(Employee employee){  					  
			logger.info("修改数据-->"+employee.toString());  							  
			FormResponse<Void> response = new FormResponse<Void>();  						  
			if(response.isSuccess()){  														  
				employeeServiceImpl.update(employee);  											  
				response.setMessage("修改成功！");  											  
			}else{  																		  
				response.setMessage("修改失败！");  											  
			}  																				  
			return response;  																  
		}  																					  
		/**  																				  
		 * 删除  																			      
		 * @param employee  															  
		 */  																				  
		@ResponseBody  																		  
		@RequestMapping("/del") 															  
		public SimpleResponse<Void> delete(Employee employee){  					  
			logger.info("删除数据-->"+employee.toString());  							  
			SimpleResponse<Void> response = new SimpleResponse<Void>();  					  
			employeeServiceImpl.delete(employee);  												  
			response.setSuccess(true);  													  
			return response;  																  
		}		 																			  
 
	 
	 
	 
	}  



